package com.hualude.roadsign.controller;

import com.hualude.roadsign.dto.*;
import com.hualude.roadsign.service.SolarEnergyManageService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * Created by shao-yikun on 2017/7/11.
 */

@Controller
@RequestMapping("/rds_solarEnergyManageController")
public class SolarEnergyManageController {
    @Resource
    private SolarEnergyManageService solarEnergyManageService;

    @RequestMapping("/getSolarEnergy4DT")
    @ResponseBody
    public DTResponseDto getSolarEnergy4DT(DTRequestDto dtRequestDto,
                                           String actorIds,
                                           Integer orgId,
                                           Boolean audit,
                                           String startRoad,
                                           String endRoad,
                                           String roadName,
                                           Integer alarmBinding) {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = solarEnergyManageService.getSolarEnergy4DT(
                    dtRequestDto, actorIds, orgId, audit, startRoad, endRoad, roadName, alarmBinding);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @RequestMapping("/getSolarEnergy4APP")
    @ResponseBody
    public JsonMsgDto getSolarEnergy4APP(String actorIds,
                                         Integer orgId,
                                         Integer mCount,
                                         Integer mSize,
                                         String city,
                                         String startRoad,
                                         String endRoad,
                                         String roadName,
                                         String alarmType) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(solarEnergyManageService.getSolarEnergy4APP(
                    actorIds, orgId, mCount, mSize, city, startRoad, endRoad, roadName, alarmType));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/addSolarEnergy")
    @ResponseBody
    public JsonMsgDto addSolarEnergy(SolarEnergyDto solarEnergyDto) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(solarEnergyManageService.addSolarEnergy(solarEnergyDto));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/deleteSolarEnergy")
    @ResponseBody
    public JsonMsgDto deleteSolarEnergy(String solarEnergyIds) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(solarEnergyManageService.deleteSolarEnergy(solarEnergyIds));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/updateSolarEnergy")
    @ResponseBody
    public JsonMsgDto updateSolarEnergy(SolarEnergyDto solarEnergyDto) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(solarEnergyManageService.updateSolarEnergy(solarEnergyDto));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/auditSolarEnergy")
    @ResponseBody
    public JsonMsgDto auditSolarEnergy(String solarEnergyIds) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(solarEnergyManageService.auditSolarEnergy(solarEnergyIds));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getRoadByRoadName")
    @ResponseBody
    public JsonMsgDto getRoadByRoadName(String roadName, Integer actorId, Integer orgId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(solarEnergyManageService.getRoadByRoadName(roadName, actorId, orgId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setJsonData(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getSectionByRoadName")
    @ResponseBody
    public JsonMsgDto getSectionByRoadName(String roadName, Integer actorId, Integer orgId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(solarEnergyManageService.getSectionByRoadName(roadName, actorId, orgId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setJsonData(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getSolarEnergyById")
    @ResponseBody
    public JsonMsgDto getSolarEnergyById(Integer solarEnergyId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(solarEnergyManageService.getSolarEnergyById(solarEnergyId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getRoad4SolarEnergy")
    @ResponseBody
    public JsonMsgDto getRoad4SolarEnergy(Integer actorId, Integer orgId, String city, Integer mCount, Integer mSize) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(solarEnergyManageService.getRoad4SolarEnergy(actorId, orgId, city, mCount, mSize));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getCity4SolarEnergy4App")
    @ResponseBody
    public JsonMsgDto getCity4SolarEnergy4App(Integer actorId, Integer orgId, Integer mCount, Integer mSize) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(solarEnergyManageService.getCity4SolarEnergy4App(actorId, orgId, mCount, mSize));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getSectionByRoadName4App")
    @ResponseBody
    public JsonMsgDto getSectionByRoadName4App(String roadName, String solarEnergyRoadName, String city, Integer actorId, Integer orgId, Integer mCount, Integer mSize) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(solarEnergyManageService.getSectionByRoadName4App(roadName, solarEnergyRoadName, city, actorId, orgId, mCount, mSize));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setJsonData(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getStartRoad4App")
    @ResponseBody
    public JsonMsgDto getStartRoad4App(String roadName, String city, Integer actorId, Integer orgId, Integer mCount, Integer mSize) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(solarEnergyManageService.getStartRoad4App(roadName, city, actorId, orgId, mCount, mSize));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setJsonData(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getSolarEnergy4Map4App")
    @ResponseBody
    public JsonMsgDto getSolarEnergy4Map4App(Integer orgId,
                                             String actorIds,
                                             double neLongitude,
                                             double neLatitude,
                                             double swLongitude,
                                             double swLatitude) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(solarEnergyManageService.getSolarEnergy4Map4App
                    (orgId, actorIds, neLongitude, neLatitude, swLongitude, swLatitude));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    /**
     * @Description:
     * @Author: WYX.
     * @Date: 2018/5/1 18:56.
     */
    @ResponseBody
    @RequestMapping("/bindingDevice")
    public JsonMsgDto bindingDevice(String deviceId, Integer solarEnergyId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(solarEnergyManageService.bindingDevice(deviceId, solarEnergyId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @ResponseBody
    @RequestMapping("/unbindingDevice")
    public JsonMsgDto unbindingDevice(String deviceId, Integer solarEnergyId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(solarEnergyManageService.unbindingDevice(deviceId, solarEnergyId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @ResponseBody
    @RequestMapping("showAlarmHistory")
    public DTResponseDto showAlarmHistory(DTRequestDto dtRequestDto, String deviceId, Integer deviceType) {
        DTResponseDto dtResponseDto = null;
        try {
            dtResponseDto = solarEnergyManageService.showAlarmHistory(dtRequestDto, deviceId, deviceType);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }
}
